﻿Imports System.IO
Imports AFS.Aspnet.Collaboration.Site.ArbAuf

Public Class WebForm1
    Inherits System.Web.UI.Page
    Private dat As String = Date.Now.ToShortDateString

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If addpagewasloaded = False Then
            Me.CalendarControl.Text = dat
            addpagewasloaded = True
        End If

        If ListOfRayone.Count = 0 Then
            InitRayone()
        End If

        'RayonCmb.DataSource = ListOfRayone
        'RayonCmb.DataBind()

        Storno.Text = "0"
        Anzeigen.Text = "0"
        TBS02.Text = "0"
        If mandateDb Is Nothing Then
            InitMandateDBFile()
        End If
        AutomaticUploadToBackYardServer.InitTimer()
    End Sub

    Private Sub Save_Click(sender As Object, e As EventArgs) Handles Save.Click

        Dim ntype As New MandateAufstellung.MandateAnzahlen
        With ntype
            .ID = System.Guid.NewGuid.ToString
            .Datum = Me.CalendarControl.Text
            .StVo = Me.StVo.Text
            .Pg = Me.Pg.Text
            .Typ = Me.DropDownList1.SelectedValue
            .Rayon = Me.RayonCmb.Text
            .Storno = Me.Storno.Text
            .Anzeigen = Me.Anzeigen.Text
            .TB02 = Me.TBS02.Text
        End With

        'Dim rettype = AddToXmlFile(Me.CalendarControl.Text, Me.StVo.Text, Me.Pg.Text, Me.DropDownList1.SelectedValue, Me.RayonCmb.Text, Me.Storno.Text, Me.Anzeigen.Text, Me.TBS02.Text)
        'If rettype.hasError = True Then
        '    Response.Write("Fehler beim Speichern des Mandates: " & rettype.Errors.Message.ToString)
        'End If
        'RefreshList()
        mandateDb.MandateAnzahlen.InsertOnSubmit(ntype)
        mandateDb.SubmitChanges()
    End Sub

    Protected Sub Edit_Click(sender As Object, e As EventArgs)
        Me.CalendarControl.Enabled = True

        Dim a = (From b In mandateDb.MandateAnzahlen
                Where b.Datum = Me.CalendarControl.Text
                Select b).FirstOrDefault

        mandateDb.MandateAnzahlen.DeleteOnSubmit(a)
        mandateDb.SubmitChanges()
        Dim ntype As New MandateAufstellung.MandateAnzahlen
        With ntype
            .ID = System.Guid.NewGuid.ToString
            .Datum = Me.CalendarControl.Text
            .StVo = Me.StVo.Text
            .Pg = Me.Pg.Text
            .Typ = Me.DropDownList1.SelectedValue
            .Rayon = Me.RayonCmb.Text
            .Storno = Me.Storno.Text
            .Anzeigen = Me.Anzeigen.Text
            .TB02 = Me.TBS02.Text
        End With

        mandateDb.MandateAnzahlen.InsertOnSubmit(ntype)
        mandateDb.SubmitChanges()
    End Sub
    Shared SelectedMandat As MandateAufstellung.MandateAnzahlen

    Protected Sub Loadit_Click(sender As Object, e As EventArgs)

        Dim mandat = (From a In listofmandate
                    Where a.Datum = Me.CalendarControl.Text
                    Select a).FirstOrDefault

        If mandat IsNot Nothing Then

            SelectedMandat = mandat

            With mandat
                Me.CalendarControl.Text = mandat.Datum
                Me.RayonCmb.Text = mandat.Rayon
                Me.StVo.Text = .StVo
                Me.Pg.Text = .Pg
                Me.DropDownList1.SelectedValue = .Typ.ToString
                Me.Anzeigen.Text = .Anzeigen
                Me.Storno.Text = .Storno
                Me.TBS02.Text = .TB02
            End With
        Else
            Response.Write("nothing selected...")
        End If
        Me.CalendarControl.Enabled = False
    End Sub




    Protected Sub deleteit_Click(sender As Object, e As EventArgs)

    End Sub

    
End Class